import { MAIN_COLOR } from '@/constant'
import { getItem } from '@/utils/storage'
import { generateColors } from '@/utils/theme'
// 快捷访问
const getters = {
  // 令牌
  token: (state) => state.user.token,
  // 用户信息
  userInfo: (state) => state.user.userInfo,
  /**
   *
   * @param {*} state
   * @returns true: 表示用户信息已存在，false: 没有登录成功
   */
  hasUserInfo: (state) => {
    // 判断用户信息是否为空,如果不为空，则认为已经登录成功，返回true
    return JSON.stringify(state.user.userInfo) !== '{}'
  },
  cssVar: (state) => {
    return {
      ...state.theme.variables,
      ...generateColors(getItem(MAIN_COLOR)),
    }
  },
  // 侧边栏是否打开
  sidebarOpened: (state) => state.app.sidebarOpened,
  // 语言
  language: (state) => state.app.language,
  // 主题色
  mainColor: (state) => state.theme.mainColor,
  // tags
  tagsViewList: (state) => state.app.tagsViewList,
}
export default getters
